using DG.Tweening;
using Spine.Unity;
using UnityEngine;

public class TinkerController : MonoBehaviour
{
	public GameObject Player;

	private float distance;

	private bool isMove;

	private Tween _tweenMove;

	private void Start()
	{
	}

	private void Update()
	{
		Vector3 position = base.transform.position;
		float x = position.x;
		Vector3 position2 = Player.transform.position;
		distance = Mathf.Abs(x - position2.x);
		if (distance > 1.5f)
		{
			_tweenMove.Kill();
			isMove = false;
			Vector3 position3 = base.transform.position;
			float x2 = position3.x;
			Vector3 position4 = Player.transform.position;
			if (x2 < position4.x)
			{
				base.transform.Translate(Vector2.right * 1.5f * Time.deltaTime);
				GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
			}
			else
			{
				base.transform.Translate(-Vector2.right * 1.5f * Time.deltaTime);
				GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
			}
		}
		else if (!isMove)
		{
			Vector3 position5 = base.transform.position;
			float x3 = position5.x;
			Vector3 position6 = Player.transform.position;
			if (x3 < position6.x)
			{
				Transform transform = base.transform;
				Vector3 position7 = Player.transform.position;
				_tweenMove = transform.DOMoveX(position7.x + 1.5f, 3f).SetEase(Ease.Linear).OnComplete(FlipMove);
				GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
			}
			else
			{
				Transform transform2 = base.transform;
				Vector3 position8 = Player.transform.position;
				_tweenMove = transform2.DOMoveX(position8.x - 1.5f, 3f).SetEase(Ease.Linear).OnComplete(FlipMove);
				GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
			}
			isMove = true;
		}
	}

	private void FlipMove()
	{
		Vector3 position = base.transform.position;
		float x = position.x;
		Vector3 position2 = Player.transform.position;
		if (x < position2.x)
		{
			Transform transform = base.transform;
			Vector3 position3 = Player.transform.position;
			_tweenMove = transform.DOMoveX(position3.x + 1.5f, 3f).SetEase(Ease.Linear).OnComplete(FlipMove);
			GetComponent<SkeletonAnimation>().skeleton.FlipX = true;
		}
		else
		{
			Transform transform2 = base.transform;
			Vector3 position4 = Player.transform.position;
			_tweenMove = transform2.DOMoveX(position4.x - 1.5f, 3f).SetEase(Ease.Linear).OnComplete(FlipMove);
			GetComponent<SkeletonAnimation>().skeleton.FlipX = false;
		}
		isMove = true;
	}
}
